package com.hexacta.hrs.test.data;

import static com.hexacta.hrs.test.data.EmployeeTestDataDependencyCreator.EMPLOYEE_1;
import static com.hexacta.hrs.test.data.EmployeeTestDataDependencyCreator.EMPLOYEE_2;

import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.vectrics.employee.Employee;

import com.hexacta.hrs.domain.mentoring.Action;
import com.hexacta.hrs.domain.mentoring.Meeting;
import com.hexacta.hrs.domain.mentoring.MeetingStatus;
import com.hexacta.hrs.domain.mentoring.PriorityTypes;
import com.hexacta.hrs.domain.mentoring.Theme;
import com.hexacta.hrs.domain.mentoring.ThemeTypes;

/**
 * Test data creator for an Meeting.
 * 
 * @author vschimpf
 */
public class MeetingTestDataCreator extends AbstractTestDataCreator {

    public MeetingTestDataCreator(final List<TestDataDependencyCreator> dependencies) {
        super(dependencies);
    }

    @Override
    protected Object internalCreateTestData(final Map<String, Object> context) {
        Meeting meeting = createMeeting(context);
        return meeting;
    }

    private Meeting createMeeting(final Map<String, Object> context) {
        Employee mentor = (Employee) loadObjectFromContext(context, EMPLOYEE_1);
        Employee employee = (Employee) loadObjectFromContext(context, EMPLOYEE_2);
        Calendar c = Calendar.getInstance();
        c.set(Calendar.MONTH, Calendar.DECEMBER);
        return createRelationshipWithFirstMeeting(mentor, employee, c.getTime(), MeetingStatus.SCHEDULED);
    }

    public Meeting createRelationshipWithFirstMeeting(final Employee mentor, final Employee employee, final Date meetingDate,
            final MeetingStatus meetingStatus) {

        if ((employee.getMentor() == null) || (!employee.getMentor().equals(mentor))) {
            //employee.addMentorAssignment(mentor, meetingDate);// Active
            // relationship
        }

        flushSession();

        Meeting meeting = new Meeting();
        meeting.setEmployee(employee);
        meeting.setMentor(mentor);
        meeting.setDate(meetingDate);
        meeting.setStatus(meetingStatus);
        meeting.setCheckedByHR(true);

        Set<Theme> noteThemes = new HashSet<Theme>();
        Theme theme = new Theme();
        theme.setName("Theme 1");
        theme.setPriority(PriorityTypes.HIGH);
        theme.setType(ThemeTypes.STAFFING);
        noteThemes.add(theme);
        theme = new Theme();
        theme.setName("Theme 2");
        theme.setPriority(PriorityTypes.MEDIUM);
        theme.setType(ThemeTypes.TRAINNING);
        noteThemes.add(theme);
        meeting.setNoteThemes(noteThemes);

        Set<Action> actions = new HashSet<Action>();
        Action action = new Action();
        action.setName("Action 1");
        actions.add(action);
        action = new Action();
        action.setName("Action 2");
        actions.add(action);
        meeting.setActionsToDo(actions);

        return meeting;
    }

}
